﻿using Contract.Domain;
using MediatR;
using Trace.Infrastructure.Repository;
using Trace.Read_WebApi.Commands;

namespace Trace.Read_WebApi.CommandHandler
{
    public class TailShowHZTraceCommandHandler : IRequestHandler<TailShowHZTraceCommand, List<Tail>>
    {
        private readonly IRepository<Tail> repository;

        public TailShowHZTraceCommandHandler(IRepository<Tail> repository)
        {
            this.repository = repository;
        }

        public async Task<List<Tail>> Handle(TailShowHZTraceCommand request, CancellationToken cancellationToken)
        {
            var result = await repository.GetListAsync(x => x.ContractNumber.Equals(request.ContractNumber));
            result = result.OrderByDescending(x => x.DateTime);
            return result.ToList();
        }
    }
}
